package cd

import "gopkg.in/yaml.v2"

type KubeConfig struct {
	APIVersion     string `yaml:"apiVersion"`
	Kind           string `yaml:"kind"`
	Preferences    Preferences
	Clusters       []Cluster `yaml:"clusters"`
	Users          []User    `yaml:"users"`
	Contexts       []Context `yaml:"contexts"`
	CurrentContext string    `yaml:"current-context"`
}

type Preferences struct{}

type Cluster struct {
	Name    string `yaml:"name"`
	Cluster ClusterInfo
}

type ClusterInfo struct {
	Server                   string `yaml:"server"`
	CertificateAuthorityData string `yaml:"certificate-authority-data"`
}

type User struct {
	Name string `yaml:"name"`
	User UserInfo
}

type UserInfo struct {
	ClientCertificateData string `yaml:"client-certificate-data"`
	ClientKeyData         string `yaml:"client-key-data"`
}

type Context struct {
	Name    string `yaml:"name"`
	Context ContextInfo
}

type ContextInfo struct {
	Cluster string `yaml:"cluster"`
	User    string `yaml:"user"`
}

func ParseYaml(yamlData []byte) (*KubeConfig, error) {
	var config KubeConfig
	if err := yaml.Unmarshal(yamlData, &config); err != nil {
		return nil, err
	}
	return &config, nil
}
